package service

import (
	"github.com/jinzhu/gorm"
	"tylnmall/models"
	"common/logger"
	"errors"
)

//获取商铺中商品的数量
func CommodityNum(id int, db gorm.DB) (err error, num int) {
	var commodity []*models.Commodity
	if err = db.Where("story_id = ?", id).Find(&commodity).Error; err != nil {
		logger.Error(err)
		err = errors.New("story not found")
		logger.Error(err)
		return err, num
	}
	return nil, len(commodity)
}

func IsStory(db gorm.DB, id int) (bool, models.Story) {
	var err error
	var story models.Story
	if err = db.Where("id = ?", id).Find(&story).Error; err != nil {
		return false, story
	}
	return true, story
}
